# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Sven-Hendrik Haase <sh@lutzhaase.com>
# Contributor: Alexandre Petitjean <alpetitjean at gmail dot com>

pkgname=mopidy
pkgver=3.4.1
pkgrel=3
pkgdesc="An extensible music server written in Python"
arch=('any')
url="https://www.mopidy.com"
license=('APACHE')
depends=('python' 'python-pykka' 'python-requests' 'gstreamer' 'python-setuptools'
         'gst-python' 'gst-plugins-good' 'gst-plugins-ugly' 'python-tornado' 'gst-plugins-base'
         'python-dbus')
checkdepends=('python-gobject' 'python-pytest' 'python-responses')
makedepends=('python-sphinx' 'python-sphinx_rtd_theme' 'git')
backup=('etc/mopidy/mopidy.conf')
source=("$pkgname-$pkgver.tar.gz::https://github.com/mopidy/mopidy/archive/v${pkgver}.tar.gz"
        'mopidy.conf'
        'logging.conf'
        'mopidy.sysusers'
        "$pkgname-$pkgver-doc-py311.patch::https://github.com/mopidy/mopidy/commit/1b7330884b996e13944e9680b0c0d01f4907b6b5.patch"
        "$pkgname-$pkgver-audio-fix.patch::https://github.com/mopidy/mopidy/commit/1b7d81ad3d8227659ca1b7e0d6bf5f7859ad664a.patch"
        )
sha512sums=('cb3271f106303415b65e4b4248995235bd16a5b795f4575206d3fd08aceb5d2e2df4c323eb84df8e50cb3785d94a258633650ebc5a5916f3dcc66dfe69f249d6'
            'eb66e8e826640a939b1ba51569ab7fab041b8b5e8823ea2d5f05596faf1de8882fd8c1c32bdb92534e759243fb5ff741bda0d2ebb3282af542d1287c8c68b5ea'
            '0c438058500ab7559baae21b03b10e2b80b10c77776b240b2100da1f4c84ea8efe24dc7a38a95034e75605eaf5d21604d13e5b8c7358778c555ddb6372a49388'
            'ff6c9f0406dfc1cc01ac6edcc6bae429342437397321ab9205ca273a63b28611d08005a0a5dba639b5ae2157a4f03a1d58c2199f7dbc6965864685b4b71f0b6f'
            '212ad0a84e3cb36a576cd4c15b1fa00a9b0fc62db20ade61ee92df5c914a67dd038f89337e61e8bf2c4e03547e071f10d257168d04ddf5b81cc9a692088f5ddf'
            '852730959d4270cd0fa74738eb1b786ec38ad5d865fbd1532cec77f51990840cecb0548c003d77d145e68313469da7228d94e05e265d92a8dc17c1031c1fd14e')

prepare() {
  cd "${pkgname}-${pkgver}"
  git apply "$srcdir/mopidy-3.4.1-doc-py311.patch"
  git apply "$srcdir/mopidy-3.4.1-audio-fix.patch"
}

build() {
  cd ${pkgname}-${pkgver}
  python setup.py build
  make -C docs html man
}

check() {
  cd ${pkgname}-${pkgver}
  python -m unittest discover -vs .
}

package() {
  cd ${pkgname}-${pkgver}
  python setup.py install --root="${pkgdir}/" --optimize=1

  install -Dm755 extra/mopidyctl/mopidyctl "${pkgdir}/usr/bin/mopidyctl"

  install -dm755 "${pkgdir}/usr/share/doc/mopidy"
  cp -r docs/_build/html "${pkgdir}/usr/share/doc/mopidy"

  install -dm755 "${pkgdir}/usr/share/man/man1/"
  gzip -n -c docs/_build/man/mopidy.1 > "${pkgdir}/usr/share/man/man1/mopidy.1.gz"

  install -dm755 "${pkgdir}/usr/share/man/man8/"
  gzip -n -c extra/mopidyctl/mopidyctl.8 > "${pkgdir}/usr/share/man/man8/mopidyctl.8.gz"

  install -Dm644 "${srcdir}/mopidy.conf" "${pkgdir}/etc/mopidy/mopidy.conf"
  install -Dm644 "${srcdir}/logging.conf" "${pkgdir}/etc/mopidy/logging.conf"

  install -Dm644 "extra/systemd/mopidy.service" "${pkgdir}/usr/lib/systemd/system/mopidy.service"
  install -Dm644 "extra/desktop/mopidy.desktop" "${pkgdir}/usr/share/applications/mopidy.desktop"

  install -dm755 -g 46 -o 46 "${pkgdir}/var/cache/mopidy"
  install -dm755 -g 46 -o 46 "${pkgdir}/var/log/mopidy"
  install -dm755 -g 46 -o 46 "${pkgdir}/var/lib/mopidy"
  install -dm755 -g 46 -o 46 "${pkgdir}/var/lib/mopidy/local"
  install -dm755 -g 46 -o 46 "${pkgdir}/var/lib/mopidy/media"
  install -dm755 -g 46 -o 46 "${pkgdir}/var/lib/mopidy/playlists"

  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm644 "${srcdir}/mopidy.sysusers" "${pkgdir}/usr/lib/sysusers.d/$pkgname.conf"
}

# vim:set ts=2 sw=2 et:
